﻿# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.10.2...3.19.4)
project(CAE)
set(BUILD_DEBUG 0)

# 编译选项ON/OFF RTSA默认关闭
option(RTSA_SUPPORT "rtsa support" OFF)

if (RTSA_SUPPORT)
    message("RTSA_SUPPORT ON")
    ADD_DEFINITIONS(-DRTSA_SUPPORT)
endif () 

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
include_directories(libs/curl/include/)
include_directories(libs/openssl/include/)
include_directories(libs/cJSON/include/)
include_directories(libs/ffmpeg/include/)
if (RTSA_SUPPORT)
include_directories(libs/rtsa/include)
endif ()

aux_source_directory(. SRC_LIST)
add_subdirectory(cae_3rd)
add_subdirectory(cae_common)
add_subdirectory(cae_service)
add_subdirectory(cae_socket)
add_subdirectory(cae_dataPipe)
add_subdirectory(cae_dataHandler)
add_subdirectory(hwsecure)
add_subdirectory(cae_agent)
# generate mock so
add_subdirectory(cae_CPHMediaEngine)
add_subdirectory(cae_CPHMediaEngineDemo)

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
        log-lib

        # Specifies the name of the NDK library that
        # you want CMake to locate.
        log)
        
if (RTSA_SUPPORT)
link_libraries(z)
link_libraries(android)
endif ()

#添加libssl静态库
add_library(ssl STATIC IMPORTED)
set_target_properties(
		ssl
		PROPERTIES IMPORTED_LOCATION
		${CMAKE_SOURCE_DIR}/libs/openssl/lib/libssl.a)

#添加libcrypto静态库
add_library(crypto STATIC IMPORTED)
set_target_properties(
		crypto
		PROPERTIES IMPORTED_LOCATION
		${CMAKE_SOURCE_DIR}/libs/openssl/lib/libcrypto.a)

##添加安卓的curl库
add_library(curl SHARED IMPORTED)
set_target_properties(
        curl
        PROPERTIES IMPORTED_LOCATION
        ${CMAKE_SOURCE_DIR}/libs/curl/lib/libcurl.so)

add_library(avcodec SHARED IMPORTED)
set_target_properties(
		avcodec
		PROPERTIES IMPORTED_LOCATION
		${CMAKE_SOURCE_DIR}/libs/ffmpeg/lib/libavcodec.so)

add_library(avformat SHARED IMPORTED)
set_target_properties(
		avformat
		PROPERTIES IMPORTED_LOCATION
		${CMAKE_SOURCE_DIR}/libs/ffmpeg/lib/libavformat.so)

add_library(avutil SHARED IMPORTED)
set_target_properties(
		avutil
		PROPERTIES IMPORTED_LOCATION
		${CMAKE_SOURCE_DIR}/libs/ffmpeg/lib/libavutil.so)

add_library(swresample SHARED IMPORTED)
set_target_properties(
		swresample
		PROPERTIES IMPORTED_LOCATION
		${CMAKE_SOURCE_DIR}/libs/ffmpeg/lib/libswresample.so)

##添加cjson库
add_library(cjson STATIC IMPORTED)
set_target_properties(
		cjson
		PROPERTIES IMPORTED_LOCATION
		${CMAKE_SOURCE_DIR}/libs/cJSON/lib/libcjson.a)
		
if (RTSA_SUPPORT)		
##添加安卓的rtsa和unitrans库文件
add_library(rtsaControl SHARED IMPORTED)
set_target_properties(
		rtsaControl
		PROPERTIES IMPORTED_LOCATION
		${CMAKE_SOURCE_DIR}/libs/rtsa/lib/librtsaControl.so)
		
add_library(unitrans SHARED IMPORTED)
set_target_properties(
		unitrans
		PROPERTIES IMPORTED_LOCATION
		${CMAKE_SOURCE_DIR}/libs/rtsa/lib/libunitrans.so)
		
add_library(rtsap2p SHARED IMPORTED)
set_target_properties(
		rtsap2p
		PROPERTIES IMPORTED_LOCATION
		${CMAKE_SOURCE_DIR}/libs/rtsa/lib/librtsap2p.so)
endif ()

link_directories(../jniLibs/${ANDROID_ABI})
link_directories(./libs/openssl/lib/)
link_directories(./libs/curl/lib/)
link_directories(./libs/cJSON/lib/)
link_directories(./libs/ffmpeg/lib/)
link_directories(./libs/rtsa/lib)
link_directories(./libs/)


message("Build...")
add_executable(
		CloudAppEngine
		CloudAppEngine.cpp
)

target_link_libraries( # Specifies the target library.
		CloudAppEngine
		ssl
		crypto
		hwsecure
		curl
		avformat
		avutil
		avcodec
		swresample
		CPHMediaEngine
		cjson
		cae_common
		cae_agent
		${log-lib}
		)

if (RTSA_SUPPORT)
	target_link_libraries(CloudAppEngine rtsaControl unitrans rtsap2p)
endif ()